package handler.impl;

import com.itextpdf.text.*;
import com.itextpdf.text.pdf.PdfPTable;
import handler.TicketService;
import util.PDFConst;
import util.PDFCreateUtil;
import vo.TicketVO;

import java.io.IOException;

public class DHZYTicketService implements TicketService {
    public Paragraph createTitle() throws IOException, DocumentException {
        return PDFCreateUtil.createTitle(PDFConst.getSimhei_nomal_10(), "动火安全作业票");
    }

    public PdfPTable createMainTable(int tableWidth, TicketVO ticketVO) throws IOException, BadElementException {
        PdfPTable table = new PdfPTable(new float[]{105, 140, 93, 142});
        table.setTotalWidth(tableWidth);
        table.setLockedWidth(true);
        Font tableFont = PDFConst.getSimhei_nomal_9();
        int columnNumber = table.getNumberOfColumns();

        table.addCell(PDFCreateUtil.createLogoCell(tableWidth, columnNumber, tableFont, ticketVO.getSpecialOperationNo()));

        table.addCell(PDFCreateUtil.createCell(tableFont, "作业申请单位"));
        table.addCell(PDFCreateUtil.createCell(tableFont, ticketVO.getAppointmentDeptName()));
        table.addCell(PDFCreateUtil.createCell(tableFont, "作业申请时间"));
        table.addCell(PDFCreateUtil.createCell(tableFont, ticketVO.getAppointmentDate()));

        table.addCell(PDFCreateUtil.createCell(tableFont, "作业内容"));
        table.addCell(PDFCreateUtil.createCell(tableFont, ticketVO.getOperationContent()));
        table.addCell(PDFCreateUtil.createCell(tableFont, "动火地点及动火部位"));
        table.addCell(PDFCreateUtil.createCell(tableFont, ticketVO.getFirePlace()));

        table.addCell(PDFCreateUtil.createCell(tableFont, "动火级别"));
        table.addCell(PDFCreateUtil.createCell(tableFont, ticketVO.getFireLevel()));
        table.addCell(PDFCreateUtil.createCell(tableFont, "动火方式"));
        table.addCell(PDFCreateUtil.createCell(tableFont, ticketVO.getFireMode()));

        table.addCell(PDFCreateUtil.createCell(tableFont, "动火人及证书编号"));
        table.addCell(PDFCreateUtil.createCell(tableFont, columnNumber - 1, 1, PDFConst.getCell_height(), ""));

        table.addCell(PDFCreateUtil.createCell(tableFont, "作业单位"));
        table.addCell(PDFCreateUtil.createCell(tableFont, ""));
        table.addCell(PDFCreateUtil.createCell(tableFont, "作业负责人"));
        table.addCell(PDFCreateUtil.createCell(tableFont, ""));

        table.addCell(PDFCreateUtil.createCell(PDFCreateUtil.createDHZYGasTable(tableWidth), columnNumber));

        table.addCell(PDFCreateUtil.createCell(tableFont, "关联的其他特殊作业及安全作业票编号"));
        table.addCell(PDFCreateUtil.createCell(tableFont, columnNumber - 1, 1, PDFConst.getCell_height(), ""));

        table.addCell(PDFCreateUtil.createCell(tableFont, "风险辨识结果"));
        table.addCell(PDFCreateUtil.createCell(tableFont, columnNumber - 1, 1, PDFConst.getCell_height(), ""));

        table.addCell(PDFCreateUtil.createCell(tableFont, "动火作业实施时间"));
        table.addCell(PDFCreateUtil.createCell(tableFont, columnNumber - 1, 1, PDFConst.getCell_height(), ticketVO.getStartDate() + " - " + ticketVO.getEndDate()));

        table.addCell(PDFCreateUtil.createCell(PDFCreateUtil.createSafeMeasureTable(tableWidth), columnNumber));

        java.util.List<PdfPTable> tableList = PDFCreateUtil.createSignTableList(tableWidth, 100, 40, tableFont,ticketVO);
        for (PdfPTable t:tableList) {
            table.addCell(PDFCreateUtil.createCell(t, columnNumber));
        }
        return table;
    }
}
